var login_url = 'http://login.telecom.mipt.ru/bin/login.cgi'; 
var logout_url = 'http://login.telecom.mipt.ru/bin/logout.cgi?';
var url = 'http://login.telecom.mipt.ru';

function login(){
	var content;
	new Ajax.Request(url,
   {
     method:'get',
	 onSuccess: function(transport){
       var response = transport.responseText || "no response text";
	   var regex = new RegExp('name=chalangeack value=(\\w+)>');
	   var chalangeack = regex.exec(response)[1];
	   var key = hex_md5(chalangeack + localStorage["password"]);
	   var dist_url = login_url + '?chalangeack=' + chalangeack + '&login=' + localStorage["login"] + '&password=' + key + '&memorize=on';
	   new Ajax.Request(dist_url,
	   {
			method:'get',
			onSuccess: function(transport){
					show_temporary_notification('Login was successful', 10000);
			},
			onFailure: function(){
					show_temporary_notification('Login was failed', 10000);
			}	
	   });
	   
      },			
	  onFailure: function(){
			show_temporary_notification('Login was failed', 10000);
	  }	
   });
}

function login_to_mipt_telecom(value){
	alert(value);
}

function logout(){
	new Ajax.Request(logout_url,
   {
     method:'get',
	 onSuccess: function(transport){
	    show_temporary_notification('Logout was successful', 10000);
	 },
     onFailure: function(){
		show_temporary_notification('Logout was failed', 10000);
	 }
   });
}